package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.KeyBasket;
import com.ruoyi.system.service.IKeyBasketService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 篮子Controller
 *
 * @author 蒼飞
 * @date 2025-02-18
 */
@RestController
@RequestMapping("/system/basket")
public class KeyBasketController extends BaseController
{
    @Autowired
    private IKeyBasketService keyBasketService;

    /**
     * 查询篮子列表
     */
    @PreAuthorize("@ss.hasPermi('system:basket:list')")
    @GetMapping("/list")
    public TableDataInfo list(KeyBasket keyBasket)
    {
        startPage();
        List<KeyBasket> list = keyBasketService.selectKeyBasketList(keyBasket);
        return getDataTable(list);
    }

    /**
     * 导出篮子列表
     */
    @PreAuthorize("@ss.hasPermi('system:basket:export')")
    @Log(title = "篮子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KeyBasket keyBasket)
    {
        List<KeyBasket> list = keyBasketService.selectKeyBasketList(keyBasket);
        ExcelUtil<KeyBasket> util = new ExcelUtil<KeyBasket>(KeyBasket.class);
        util.exportExcel(response, list, "篮子数据");
    }

    /**
     * 获取篮子详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:basket:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(keyBasketService.selectKeyBasketById(id));
    }

    /**
     * 新增篮子
     */
    @PreAuthorize("@ss.hasPermi('system:basket:add')")
    @Log(title = "篮子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KeyBasket keyBasket)
    {
        return toAjax(keyBasketService.insertKeyBasket(keyBasket));
    }

    /**
     * 修改篮子
     */
    @PreAuthorize("@ss.hasPermi('system:basket:edit')")
    @Log(title = "篮子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KeyBasket keyBasket)
    {
        return toAjax(keyBasketService.updateKeyBasket(keyBasket));
    }

    /**
     * 删除篮子
     */
    @PreAuthorize("@ss.hasPermi('system:basket:remove')")
    @Log(title = "篮子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(keyBasketService.deleteKeyBasketByIds(ids));
    }
}
